#include "../mqserver/Exchange.hpp"
#include <gtest/gtest.h>
#include <iostream>
#include <unordered_map>
using namespace std;
mq::ExchangeManager::ExchangeManagerPtr emp;
class ExchangeTest : public testing::Environment
{
public:
    virtual void SetUp() override
    {
        emp = make_shared<mq::ExchangeManager>("./data/test.db");
        cout << "测试环境初始化" << endl;
    }
    virtual void TearDown() override
    {
        emp->clear();
        cout << "测试环境清理" << endl;
    }
};
// TEST(exchange, insert_test)
// {
//     unordered_map<string, string> args({{"k1", "v1"}, {"k2", "v2"}});
//     emp->declareExchange("exchange1", mq::ExchangeType::DIRECT, true, true, args);
//     emp->declareExchange("exchange2", mq::ExchangeType::TOPIC, true, true, args);
//     emp->declareExchange("exchange3", mq::ExchangeType::FANOUT, true, true, args);
//     emp->declareExchange("exchange4", mq::ExchangeType::TOPIC, true, true, args);
//     ASSERT_EQ(emp->size(), 4);
// }

// TEST(exchange, select_test)
// {
//     auto it = emp->selectExchange("exchange3");
//     ASSERT_NE(it.get(), nullptr);
//     ASSERT_EQ(it->_name, string("exchange3"));
//     ASSERT_EQ(it->_type, mq::ExchangeType::FANOUT);
//     ASSERT_EQ(it->_durable, true);
//     ASSERT_EQ(it->_auto_delete, true);
//     // ASSERT_EQ(it->getArgs(), "k2=v2&k1=v1&");
// }
TEST(exchange, delete_test)
{
    emp->deleteExchange("exchange2");
    auto it = emp->selectExchange("exchange2");
    ASSERT_EQ(emp->exists("exchange1"), true);
    ASSERT_EQ(emp->exists("exchange2"), false);
    ASSERT_EQ(emp->exists("exchange3"), true);
    ASSERT_EQ(emp->exists("exchange4"), true);
}
// TEST(exchange, recovery_test)
// {
//     ASSERT_EQ(emp->exists("exchange1"), true);
//     ASSERT_EQ(emp->exists("exchange2"), false);
//     ASSERT_EQ(emp->exists("exchange3"), true);
//     ASSERT_EQ(emp->exists("exchange4"), true);
// }
int main(int argc, char *argv[])
{
    testing::AddGlobalTestEnvironment(new ExchangeTest);
    testing::InitGoogleTest(&argc, argv);
    return RUN_ALL_TESTS();
}